package com.github.shiqiyue.learn.guava;

import com.google.common.primitives.Shorts;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/***
 * Shorts测试
 * @author wenyao.wu
 * @date 2018/7/3
 */
public class ShortsTest {

    private static final Logger logger = LoggerFactory.getLogger(ShortsTest.class);

    public static void main(String[] args) {
        short[] shortArray = {1, 2, 3, 4, 5, 6, 7, 8, 9};

        //convert array of primitives to array of objects
        List<Short> objectArray = Shorts.asList(shortArray);
        logger.info("{}", objectArray);

        //convert array of objects to array of primitives
        shortArray = Shorts.toArray(objectArray);
        logger.info("{}", shortArray);
        short data = 5;
        //check if element is present in the list of primitives or not
        logger.info("5 is in list? {}", Shorts.contains(shortArray, data));

        //Returns the minimum
        logger.info("Min: {}", Shorts.min(shortArray));

        //Returns the maximum
        logger.info("Max: {}", Shorts.max(shortArray));
        data = 2400;
        //get the byte array from an integer
        byte[] byteArray = Shorts.toByteArray(data);
        logger.info("{}", byteArray);
    }
}
